home *** CD-ROM | disk | FTP | other *** search
- ╚
- // Demonstration file for X(PLORE) - Version 4
- 1
-
- 1
- // This file demonstrates only those features
- 1
- that are new to X(PLORE). The file
- 2
- DEMO1.XPL demonstrates the features that
- 3
- were already present in CC--The Calculus
- 4
- Calculator
- 5
-
- 1
- // Matrices
- 1
-
- 1
- A = {1,2,3;4,5,6;7,9,8} // 3 x 3 matrix
- 1
-
- 1
- B = A" // Transpose of A
- 1
-
- 1
- A + B // Sum
- 1
-
- 1
- A*B // Product
- 1
-
- 1
- A^(-1) // inverse of A
- 1
-
- 1
- A/B // A*B^(-1)
- 1
-
- 1
- A\B // A^(-1)*B
- 1
-
- 1
- A = Random(3,5) // 3 x 5 matrix
- 1
-
- 1
- B = RREF(A) // Row reduced form
- 1
-
- 1
- C = B[1:3, 4:5] // submatrix
- 1
-
- 1
- H = Matrix(1/(i+j-1),i = 1 to 4, j = 1 to 4)
- 1
- // Hilbert Matrix
- 1
-
- 1
- H^3 // third power
- 1
-
- 1
- 1/H // inverse of H
- 1
-
- 1
- P = CharPoly(H) // Characteristic
- 1
- polynomial
- 2
-
- 1
- E = EigenVal(H) // Eigenvalues
- 1
-
- 1
- Rank(H - E[1]*Eye(4)) // Should be 3, since
- 1
- matrix - eigenvalue
- 2
- is singular
- 3
- F = Eig(H) // F[1] is diagonal
- 1
- matrix of eigen-
- 2
- values, F[2] has
- 3
- eigenvectors in
- 4
- its columns.
- 5
- F[2]*F[1]/F[2] - H // Should be 0 or
- 1
- nearly 0
- 2
-
- 1
- // Level Curves
- 1
-
- 1
- // We will graph the solution to
- 1
- 3 3
- 2
- x + y = 1
- 3
-
- 1
- Window(-3,3,-2,2)
- 1
- LevelC(x^3 + y^3 = 1, x=1, y=1)
- 1
-
- 1
- // This level curve is a trajectory through
- 1
- 2 2
- 2
- the vector field (3y , - 3x ). Let's take
- 3
- a look at this vector field
- 4
-
- 1
- Field(3y^2, -3x^2, x, y)
- 1
-
- 1
- // Another trajectory through this field
- 1
- starts at (-1.1, 1)
- 2
-
- 1
- Traj(3y^2, -3x^2, x=-1.1, y=1, 100)
- 1
-
- 1
- // Infinite precision numbers
- 1
-
- 1
- // A number preceded by & is called an
- 1
- infinite precision value and will be
- 2
- maintained to infinite precision. All
- 3
- computations with infinite precision values
- 4
- results in infinite precision values, and
- 5
- quotients of infinite precision values are
- 6
- stored as exact fractions reduced to lowest
- 7
- terms.
- 8
-
- 1
- x = &3/&5 // fraction
- 1
-
- 1
- y = &7/4 - &2/3 // exact arithmetic
- 1
-
- 1
- z = &3^100 // huge integers
- 1
-
- 1
- w = &100! // very huge integers
- 1
-
- 1
- H = Matrix(1/Fix(i+j-1),i = 1 to 4, j = 1 to 4)
- 1
- // 4 x 4 Hilbert matrix. The function
- 1
- FIX returns a Big Number. Its
- 2
- complement is FLOAT
- 3
-
- 1
- H*H // exact product
- 1
-
- 1
- 1/H // exact inverse of H
- 1
-
- 1
- // New Three Dimensional Graphing Commands
- 1
-
- 1
- Curve3d(cos(t), sin(t), t, t= 0 to 4pi)
- 1
- // new command for parametric curves
- 1
-
- 1
- H = Random(6,6)
- 1
- Matrixg(H)
- 1
- // New command: Graph the data in a matrix
- 1
-
- 1
- // New string operations
- 1
-
- 1
- q1 = 'abc'|'de' // concatenation
- 1
- q2 = q1[3] // single character
- 1
- q3 = q1[2:4] // substring
- 1
- q4 = upcase(q1) // upper case transform
- 1
- n = pos('de',q1) // position of substring
- 1
- m = asc(q1) // list of ascii codes
- 1
- q5 = chr(m) // characters from codes
- 1
- n1 = val('123 + cos(4)')
- 1
- // value of a string
- 2
- q6 = str(123+cos(4))
- 1
- // string from a value
- 2
-
- 1
- // See subroutine Intersect for new Input@
- 1
- command
- 2
-
- 1
- Intersect
- 1
-
- 1
- ╚
- // procedure demonstrating use of Input@
- 1
-
- 1
- Procedure Intersect
- 1
- // user finds intersection of two curves
- 1
- Window(0,3,-1,1)
- 1
- graphics
- 1
- quickg(cos(x),x)
- 1
- sk(x,x)
- 1
- solve(cos(b)=b,b=1) // target for user to guess
- 1
- Write@(.1,-.5,'Move crosshairs to intersection of curves, and')
- 1
- Write@(.1,-.6,'enter x-coordinate where curves intersect')
- 1
- Repeat
- 1
- input@(.3,-.8,5,x)
- 1
- ok = x > (b-0.05) and x < (b+0.05)
- 1
- if not ok
- 1
- beep
- 1
- end
- 1
- until ok
- 1
- write@(.1,-.7,x)
- 1
- write@(.1,-.8,'You got it!!')
- 1
- text
- 1
- end // Intersect
- 1
- ╚
-